package cn.lijiajia3515.starter.web.autoconfigure.exception;

import cn.lijiajia3515.cairo.core.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Slf4j(topic = "[ExceptionHandler]")
@ControllerAdvice(annotations = Controller.class)
@Configuration(proxyBeanMethods = false)
@Order(200)
public class CairoExceptionHandlerAutoConfiguration {

    @ExceptionHandler(BusinessException.class)
    public void statusException(BusinessException bex, HttpServletRequest request, HttpServletResponse response) {
        throw bex;
    }

    @ExceptionHandler(RuntimeException.class)
    public void runtimeException(RuntimeException e, HttpServletRequest request) {
        throw e;
    }


    @ExceptionHandler(Exception.class)
    public void exception(Exception e, HttpServletRequest request) throws Exception {
        throw e;
    }

}
